<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 4:31
 */
namespace app\blog\controller;
use app\blog\model\SetmealModel as se;
use cmf\controller\AdminBaseController;

class SetmealController extends AdminBaseController{
    /**
     * 套餐列表页面
    */
    public function _initialize()
    {
        parent::_initialize();
        $this->se=new se();
    }

    public function index(){
        $param = $this->request->param('set_name');
        //获取商品所有商品套餐
        $rest       = $this->se->index($param);
        $this->assign('data',$rest['data']);
        $this->assign('page',$rest['page']);
        return $this->fetch('setmeal/index');
    }
    /**
     * 套餐添加页面
    */
    public function add(){
        $shop=$this->se->session();
        $this->assign('shop',$shop);
        return $this->fetch('setmeal/add');
    }
    /*商品选择*/
    public function addgoods()
    {
        $date=$this->request->param();
        $goods=$this->se->addgoods($date);
        $this->assign('date',$goods['data']);
        $this->assign('page',$goods['page']);
        return $this->fetch('setmeal/goodsmeal');
    }
    /*确认商品*/
    public function set()
    {
       $date=$_POST['date'];
       $date=explode(',',$date);
       $goods=array();
       foreach ($date as $k=>$v)
       {
           if(!empty($v))
           {
               $where['goods_guid']=$v;
               $goods_name=$this->se->getgoods($where);
               $goods[$k]=$goods_name;
           }
       }
       $goods=implode(',',$goods);
       $this->success($goods);
    }
    /**
     * 套餐添加操作
    */
    public function addpost(){
        $date       = $this->request->param();
        $rest       = $this->se->add($date);
        if($rest == 1){
            $this->success('添加成功！','setmeal/index');
        }else{
            $this->error('添加失败');
        }

    }
    /**
     * 套餐修改页面
    */
    public function detail(){
        //根据id获取该条套餐信息
        $array          = $this->request->param();
        $where['set_guid']=$array['set_guid'];
        $rest        = $this->se->getgcone($where);
        $this->assign('data',$rest);
        return $this->fetch('detail');
    }
    /**
     * 套餐修改操作
    */
    public function detailpost(){
        $date        = $this->request->param();
        $rest        = $this->se->detail($date);
        if($rest != false){
            $this->success("操作成功！",url("setmeal/index"));
        }else{
            $this->error('操作失败');
        }
    }
    /**
     * 套餐删除操作
    */
    public function del(){
        $date        = $this->request->param();
        $rest        = $this->se->del($date);
        if($rest['num'] != 0){
            $this->success($rest['con'],url("setmeal/index"));
        }else{
            $this->error($rest['con'],url("setmeal/index"));
        }
    }
}